package com.buyingtickets.controller;

import com.buyingtickets.dao.PassengersDao;
import com.buyingtickets.entity.Passenger;
import com.buyingtickets.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class AddPersonAction {
    @Resource
    private PassengersDao passengersDao;

    @RequestMapping("toaddpersion")
    public  String add(){
        return "addppassenger";
    }
    @RequestMapping("toaddpersion1")
    public  String add1(){
        return "addppassenger2";
    }

    @RequestMapping("addpersion")
    public String AddPersonAction(Passenger passenger, Model model, HttpSession httpSession) {
        User user=(User) httpSession.getAttribute("User");
        passenger.setUser(user);
        boolean falg=passengersDao.AddPassenger(passenger);
        passenger.setUser(user);
        return "redirect:/order/"+ httpSession.getAttribute("siteStart")+httpSession.getAttribute("siteEnd")+httpSession.getAttribute("trainNumberId")+httpSession.getAttribute("startDate")+httpSession.getAttribute("trainNumberId")+"/trainOrderInfo";
    }
    @RequestMapping("addpersion2")
    public String AddPersonAction2(Passenger passenger, Model model, HttpSession httpSession) {
        User user=(User) httpSession.getAttribute("User");
        passenger.setUser(user);
        boolean falg=passengersDao.AddPassenger(passenger);
        int id= (int) httpSession.getAttribute("tofcid");
        passenger.setUser(user);
        return "redirect:/order/"+ httpSession.getAttribute("siteStart")+httpSession.getAttribute("siteEnd")+httpSession.getAttribute("trainNumberId")+httpSession.getAttribute("startDate")+httpSession.getAttribute("trainNumberId")+"/exchangeTrainOrderInfo";
    }
}
